package com.mjf.transformation

import org.apache.flink.api.common.RuntimeExecutionMode
import org.apache.flink.streaming.api.scala._

/**
 * union：将多个流【必须是同一类型的流】合并为一个流，相当于SQL中的union all
 */
object UnionDemo {
  def main(args: Array[String]): Unit = {

    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
    env.setParallelism(1)
    env.setRuntimeMode(RuntimeExecutionMode.BATCH)

    val source1: DataStream[String] = env.fromCollection(List("hello world", "hello java"))

    val source2: DataStream[String] = env.fromCollection(List("hello hadoop", "spark  flink"))

    val source3: DataStream[String] = env.fromCollection(List("hive spark", "hello world"))

    source1.print("source1")
    source2.print("source2")
    source3.print("source3")

    val result: DataStream[String] = source1.union(source2, source3)

    result.print("result")

    env.execute(UnionDemo.getClass.getName)

  }
}
